home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / tp.zip / TP.ASM < prev    next >
Assembly Source File  |  1987-08-19  |  8KB  |  203 lines

  1. code    Segment Para
  2.         Assume cs:code, ds:code
  3.         org     100h
  4. park    proc far
  5.         jmp     init
  6. x1Coff  dw      0                  ; All of the old INT vectors and
  7. x1Cseg  dw      0                  ;   scratch data space
  8. x13off  dw      0
  9. x13seg  dw      0
  10. parked  dw      0
  11. count   dw      0
  12. value   dw      0
  13. flag    dw      0
  14. oldax   dw      0
  15. oldip   dw      0
  16. oldcs   dw      0
  17. oldflgs dw      0
  18.  
  19.         even                       ; Start the assembler off on an even foot
  20.  
  21. x1Cint: push    ax                 ; Start of the patched INT1C handler
  22.         push    bx
  23.         push    cx
  24.         push    dx
  25.         push    ds
  26.         mov     ax,cs              ; Set code=data segments
  27.         mov     ds,ax              ;
  28.         xor     ax,ax              ; Clear AX
  29.         cmp     parked,ax          ; Compare PARKED to 0
  30.         jne     x1Cext             ; Exit if already PARKED
  31.         dec     word ptr count     ; Reduce time until PARK
  32.         cmp     count,ax           ; Is it time to PARK?
  33.         jne     x1Cext             ; Exit if not time
  34.         cmp     flag,1             ; Has disk been used recently?
  35.         je      x1Cext             ; Exit if so
  36.         cli                        ; Block any interrupts
  37.         mov     ax,1               ; Okay, we're going to PARK the drives
  38.         mov     parked,ax          ; Set PARKED flag
  39.         mov     flag,ax            ; Set FLAG (we're suppose to do something)
  40.         mov     ax,value           ; Reset counter to magic number * PARAMETER
  41.         mov     count,ax
  42.         pop     ds
  43.         pop     dx
  44.         pop     cx
  45.         pop     bx
  46.         pop     ax
  47.         mov     cs:oldax,ax        ; Prepare to call to 'old'
  48.         pop     ax      ;ip        ;   INT13 handler
  49.         mov     cs:oldip,ax
  50.         pop     ax      ;cs
  51.         mov     cs:oldcs,ax
  52.         pop     ax      ;flags
  53.         mov     cs:oldflgs,ax
  54.         mov     ax,offset parks
  55.         pushf                      ; Generate a return to the PARKER ??
  56.         push    cs
  57.         push    ax
  58.         mov     ax,cs:oldax
  59.         sti
  60.         jmp     dword ptr cs:[x1Coff]    ; Call the 'old' INT1C handler
  61. x1Cext: pop     ds                       ; Set up to leave the new
  62.         pop     dx                       ;   INT1C handler
  63.         pop     cx
  64.         pop     bx
  65.         pop     ax
  66. x1Cou1: jmp     dword ptr cs:[x1Coff]    ; Leave the new INT1C handler
  67.  
  68. parks:  sti
  69.         push    ax
  70.         push    cx
  71.         push    dx
  72.         push    ds
  73.         mov     ax,cs
  74.         mov     ds,ax
  75.  
  76. ;       Do the BIOS's dirty work so this code will work!
  77.  
  78.         mov     al,020h       ; Write something to 8259A interrupt
  79.         out     020h,al       ;   controller chip
  80.  
  81.         mov     ah,08         ; Get disktable parameters
  82.         mov     dx,80h
  83.         int     13h
  84.         mov     dx,80h        ; Set N heads to 8, drive to 0
  85.         inc     ch            ;   and set to ?next? cylinder
  86.         jnc     p1
  87.         add     cl,40h        ; Add 40 to cylinder count if
  88. p1:     mov     ax,0c01h      ;   N cylinders > 256
  89.         int     13h           ; Seek to sector to PARK drive
  90.  
  91.         mov     ah,08         ; Get disktable parameters
  92.         mov     dx,81h
  93.         int     13h
  94.         mov     dx,81h        ; Set N heads to 8, drive to 1
  95.         inc     ch            ;   and set to ?next? cylinder
  96.         jnc     p2
  97.         add     cl,40h        ; Add 40 to cylinder count if
  98. p2:     mov     ax,0c01h      ;   N cylinders > 256
  99.         int     13h           ; Seek to sector to PARK drive
  100.  
  101.         xor     ax,ax
  102.         mov     flag,ax       ; We've done something, so clear 
  103.         pop     ds            ;   something to do flag
  104.         pop     dx
  105.         pop     cx
  106.         mov     ax,cs:oldflgs         ; Save the current registers
  107.         push    ax
  108.         popf
  109.         pop     ax
  110.         jmp     dword ptr cs:[oldip]  ; Jump off to handle the disk I/O
  111.  
  112. x13int: push    ax            ; Start of the patched INT13 handler
  113.         push    ds
  114.         sti
  115.         mov     ax,cs
  116.         mov     ds,ax
  117.         cmp     flag,1        ; Are we waiting to park the drives ?
  118.         je      x13in1        ; If so, and the disk is being used,
  119.         mov     ax,value      ;   reset the timer and PARKED flags
  120.         mov     count,ax
  121.         xor     ax,ax
  122.         mov     parked,ax
  123. x13in1: pop     ds
  124.         pop     ax
  125.         jmp     dword ptr cs:[x13off]
  126.         dw      0
  127. table   dw      0             ; Just a label to tell where to cut the
  128.                               ;   program for the TSR interrupt to DOS
  129.  
  130. init:   xor     ax,ax                   ; Clear AX
  131.         mov     parked,ax               ; Clear PARKED flag
  132.         mov     bx,80h                  ; Set up for DOS call
  133.         mov     al,[bx]                 ; Read in PARAMETER from DTA
  134.         cmp     al,0
  135.         jne     init1
  136.         int     21h                     ; DO NOTHING exit if 0 length
  137. init1:  inc     bx                      ; Check for SPACE
  138.         mov     al,[bx]
  139.         cmp     al,32
  140.         je      init1                   ; If SPACE, loop
  141.         cmp     al,13                   ; Check for CR
  142.         jne     init3                   ; If CR, DO NOTHING exit
  143. init2:  xor     ax,ax
  144.         int     21h
  145. init3:  cmp     al,49                   ; Exit if below PARAMETER is
  146.         jb      init2                   ;   below 1 or above 9
  147.         cmp     al,57
  148.         ja      init2
  149.         lea     dx,mess                 ; Tell world we're installing...
  150.         mov     cx,ax
  151.         mov     ah,09                   ; Reset the disk table vectors
  152.         int     21h                     ;   to be sure of the old values
  153.         mov     ax,cx                   ; Recover PARAMETER saved in CX
  154.         xor     ah,ah                   ; Clear AH
  155.         mov     bx,0fh
  156.         and     ax,bx                   ; Set AX to 0F AND PARAMETER
  157.         mov     dx,2182                 ; Enter some magic number of ticks
  158.                                         ; 1091 = Compaq Deskpro 8086 @ 7.2MHz
  159.                                         ;  443 hex
  160.                                         ; 10910 = about 10:1 over above
  161.                                         ;  2A9E hex
  162.         mul     dx                      ; Get count for wait loop
  163.         mov     value,ax                ; Save the value
  164.         mov     count,ax                ; Update counter
  165.         cli                             ; Okay, no interrupts while we play
  166.         push    es                      ;   with DOS and the machines brains
  167.         xor     ax,ax                   ; Move into place all the new
  168.         mov     es,ax                   ;   INT vectors
  169.         mov     bx,76
  170.         mov     ax,es:[bx]
  171.         mov     x13off,ax
  172.         mov     ax,offset x13int
  173.         mov     es:[bx],ax
  174.         inc     bx
  175.         inc     bx
  176.         mov     ax,es:[bx]
  177.         mov     x13seg,ax
  178.         mov     ax,cs
  179.         mov     es:[bx],ax
  180.         xor     ax,ax
  181.         mov     flag,ax
  182.         mov     es,ax
  183.         mov     bx,112
  184.         mov     ax,es:[bx]
  185.         mov     x1Coff,ax
  186.         mov     ax,offset x1Cint
  187.         mov     es:[bx],ax
  188.         inc     bx
  189.         inc     bx
  190.         mov     ax,es:[bx]
  191.         mov     x1Cseg,ax
  192.         mov     ax,cs
  193.         mov     es:[bx],ax
  194.         pop     es
  195.         sti                         ; Okay, we're done setting the new vectors
  196.         mov     dx,offset table     ; Set the length to keep in memory
  197.         int     27h                 ; Terminate the program STAY RESIDENT !
  198.  
  199. mess    db      ' -------- Installing TIMEPARK Utility -------- ',13,10,'$'
  200. park    endp
  201. code    ends
  202.         end park
  203.